package top.yekongle.shop.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Hank Lau
 * @date 2022/5/2
 */
@EnableOpenApi
@Configuration
public class SwaggerConfig {

	/**
	 * swagger2的配置文件，这里可以配置swagger2的一些基本的内容，比如扫描的包等等
	 * @author kevin
	 * @return springfox.documentation.spring.web.plugins.Docket
	 *
	 */
	@Bean
	public Docket createRestApi() {
		// swagger设置，基本信息，要解析的接口及路径等
		return new Docket(DocumentationType.OAS_30)
				.apiInfo(apiInfo())
				.select()
				//设置通过什么方式定位需要自动生成文档的接口，这里定位方法上的@ApiOperation注解
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				//接口URI路径设置，any是全路径，也可以通过PathSelectors.regex()正则匹配
				.paths(PathSelectors.any())
				.build();
	}

	/**
	 * 生成接口信息，包括标题、联系人，联系方式等
	 *
	 */
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("SpringBoot Shop Demo")
				.description("Shop sample")
				.version("1.0.0")
				.contact(new Contact("kevin", "https://www.poweratom.top", "973352916@qq.com"))
				.build();
	}
}
